<template>
<div>
  <h1>新闻添加</h1>
  <p>标题:<input type="text" v-model="form.headline"></p>
  <p>内容:<input type="text" v-model="form.content"></p>
  <p>
    <button @click="add">添加</button>
  </p>

  <h1>新闻展示</h1>
  <table border="1" cellspacing="0" align="center">
    <tr>
      <td>标题</td>
      <td>内容</td>
    </tr>
    <tr v-for="i in newlist">
      <td>{{i.headline}}</td>
      <td>{{i.content}}</td>
    </tr>
    <tr>
      <td>
        <button v-for="i in tpages" @click="get_new(i)">{{i}}</button>
      </td>
    </tr>
  </table>
</div>
</template>

<script>
export default {
  name: "New",
  data(){
    return{
      form:{},
      newlist:[],
      tpages:[],
    }
  },
  methods:{
    add(){
      this.axios.post('userm/ne/',this.form)
      .then(res=>{
        console.log(res.data)
      })
    },
    get_new(cpage){
      this.axios.get('userm/ne/?cpage='+cpage)
      .then(res=>{
        this.newlist=res.data.newlist
        this.tpages=res.data.tpages
      })
    },
  },
  mounted() {
    this.get_new(1)
  }
}
</script>

<style scoped>

</style>
